<?php
class DashboardController extends AppController {
	var $name = 'Dashboard';
	var $uses = array('User', 'Group','Analytic');


	function beforeRender(){
		parent::beforeRender();
		$this->set('menu_parent', 'Dashboard');
		$this->set('menu_subactive', '');
	}
	
	function admin_index(){
		 
		$this->set("CSS", "dashboard");
		$this->__getUserOnline();
		if($today = $this->Analytic->getTodayVisitors());
		{
			$this->set("today",$today);
		}
	}

	function __getUserOnline(){
		$limit_time = time() - 300;
		 

		$condition_not_member = array (
			"and" => array (
				"activity >=" => $limit_time,
				"member = 'n'"
				));
		$condition_member = array (
			"and" => array (
				"activity >=" => $limit_time,
				"member = 'y'"
				));

		// We can add group by Ip_address for a better result 
		$OnlineNotMember =  $this->Whoonline->find('count',array('conditions' => $condition_not_member,'group'=>'ip_address'));
		$WhoOnlineMember = $this->Whoonline->find('all',array('conditions' => $condition_member));
		$OnlineMember = 0;
		
		if(!$OnlineNotMember) 	$OnlineNotMember = 0;
		if($WhoOnlineMember) {
			$OnlineMember = count($WhoOnlineMember);
		}		
		
		$this->set("OnlineNotMember",$OnlineNotMember);
		$this->set("OnlineMember",$OnlineMember);
		$this->set("Members",$WhoOnlineMember);
		$this->set("TotalOnline",$OnlineNotMember+$OnlineMember);
		
	}

}